﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace DescriptionStrategyPlugin
{
    public class DescrCustomFormatting : AssemblyExplorer.DefaultDescriptionStrategy
    {
        private string _format;

        public DescrCustomFormatting()
        {
            _format = "_imageList.Images.Add(ReflectionItems.{0}, Color.Magenta); _indexes.Add(\"{1}\", {2});{3}";
        }

        public string FormatString
        {
            get { return _format; }
            set { _format = value; }
        }

        public override string GetTypeDesription(Type type)
        {
            StringBuilder sb = new StringBuilder();
            int k = 0;
            foreach (PropertyInfo pi in type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Static))
            {
                string name = pi.Name;
                if (!name.StartsWith("VSObject_")) continue;
                string key = name.Substring(9);
                sb.AppendFormat(_format, name, key, k, Environment.NewLine);
                k++;
            }
            return sb.ToString();
        }
    }
}
